<%@ page import="com.pubg.entity.ProductType" %>
<%@ page import="java.util.List" %>
<%@ page import="com.pubg.entity.Product" %>
<%@ page import="com.pubg.vo.PageVo" %>
<%@ page import="com.pubg.entity.User" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" +
            request.getServerName() + ":" +
            request.getServerPort() + path + "/";
%>
<html class="no-js">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>PUBG后台管理页面</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="renderer" content="webkit">
    <link rel="icon" type="image/png" href="<%=basePath%>assets/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="<%=basePath%>assets/i/app-icon72x72@2x.png">
    <link rel="stylesheet" href="<%=basePath%>assets/css/amazeui.min.css"/>
    <link rel="stylesheet" href="<%=basePath%>assets/css/admin.css">
    <script src="<%=basePath%>assets/js/jquery.min.js"></script>
    <script src="<%=basePath%>assets/js/app.js"></script>
</head>
<header class="am-topbar admin-header">
    <%
        List<ProductType> typeList = (List<ProductType>) session.getAttribute("typeList");
        if (typeList == null) {
            response.sendRedirect(basePath + "product?opr=typeList");
            return;
        }
    %>
    <%
        PageVo<Product> pageVo = (PageVo<Product>) session.getAttribute("pageVo");
        if (pageVo == null) {
            String name = "";
            response.sendRedirect(basePath + "product?opr=productList&pageSize=8&name=" + name);
            return;
        }
        User user_admin = (User) session.getAttribute("user_admin");
    %>


    <div class="am-topbar-brand"><img src="<%=basePath%>assets/i/logo.png"></div>

    <div class="am-collapse am-topbar-collapse" id="topbar-collapse">
        <ul class="am-nav am-nav-pills am-topbar-nav admin-header-list">

            <li class="am-dropdown tognzhi" data-am-dropdown>
                <button class="am-btn am-btn-primary am-dropdown-toggle am-btn-xs am-radius am-icon-bell-o"
                        data-am-dropdown-toggle> 消息管理<span class="am-badge am-badge-danger am-round">1</span></button>
                <ul class="am-dropdown-content">
                    <li class="am-dropdown-header">所有消息都在这里</li>

                    <li><a href="#">欢迎回到PUBG后台管理系统!<span class="am-badge am-badge-danger am-round">1</span></a></li>

                </ul>
            </li>

            <li class="kuanjie">

                <a href="#">会员管理</a>
                <a href="#">奖金管理</a>
                <a href="#">订单管理</a>
                <a href="#">产品管理</a>
                <a href="<%=basePath%>index.jsp">PUBG首页</a>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            </li>

            <li class="soso">

                <p>


                </p>

            </li>

        </ul>
    </div>
</header>

<!--固定部分Begin-->
<div class="nav-navicon admin-main admin-sidebar">

    <!--管理员名称未修改-->
    <div class="sideMenu am-icon-dashboard" style="color:#aeb2b7; margin: 10px 0 0 0;"> 欢迎系统管理员：<%=user_admin.getLoginName()%></div>
    <div class="sideMenu">
        <h3 class="am-icon-flag"><em></em> <a href="javascript:(0)" onclick="productListButton(this)">商品管理</a></h3>
        <ul>
            <li><a href="">商品列表</a></li>
            <li class="func" dataType='html' dataLink='msn.htm' iconImg='images/msn.gif'><a
                    href="javascript:(0)" onclick="addProductButton(this)">添加新商品</a></li>
            <li>商品分类</li>
            <li>商品回收站</li>
            <li>库存管理</li>
        </ul>
        <h3 class="am-icon-cart-plus"><em></em> <a href="#"> 订单管理</a></h3>
        <ul>
            <li>订单列表</li>
            <li>订单打印</li>
            <li>添加订单</li>
            <li>发货单列表</li>
            <li>换货单列表</li>
        </ul>
        <h3 class="am-icon-users"><em></em> <a href="#">会员管理</a></h3>
        <ul>
            <li>会员列表</li>
            <li>未激活会员</li>
            <li>团队系谱图</li>
            <li>会员推荐图</li>
            <li>推荐列表</li>
        </ul>
        <h3 class="am-icon-volume-up"><em></em> <a href="#">信息通知</a></h3>
        <ul>
            <li>站内消息 /留言</li>
            <li>短信</li>
            <li>邮件</li>
            <li>微信</li>
            <li>客服</li>
        </ul>
        <h3 class="am-icon-gears"><em></em> <a href="#">系统设置</a></h3>
        <ul>
            <li>权限</li>
            <li>网站设置</li>
            <li>第三方支付</li>
            <li>提现 /转账 出入账汇率</li>
        </ul>
    </div>
    <!-- sideMenu End -->

    <script type="text/javascript">
        jQuery(".sideMenu").slide({
            titCell: "h3", //鼠标触发对象
            targetCell: "ul", //与titCell一一对应，第n个titCell控制第n个targetCell的显示隐藏
            effect: "slideDown", //targetCell下拉效果
            delayTime: 300, //效果时间
            triggerTime: 150, //鼠标延迟触发时间（默认150）
            defaultPlay: true,//默认是否执行效果（默认true）
            returnDefault: true //鼠标从.sideMen移走后返回默认状态（默认false）
        });
    </script>

</div>
<!--固定部分End-->


<div class="admin">
    <div class="admin-biaoge">

        <%--商品列表开始--%>
        <div id="productList">
            <div class="admin-biaogelist">

                <div class="listbiaoti am-cf">
                    <ul class="am-icon-flag on"> 商品列表</ul>

                    <dl class="am-icon-home" style="float: right;"> 当前位置： 首页 > <a href="#">商品列表</a></dl>

                </div>

                <div class="am-btn-toolbars am-btn-toolbar am-kg am-cf">
                    <ul>
                        <li style="margin-right: 0;">
                            <span class="tubiao am-icon-calendar"></span>
                            <input type="text" class="am-form-field am-input-sm am-input-zm  am-icon-calendar"
                                   placeholder="开始日期" data-am-datepicker="{theme: 'success',}" readonly/>
                        </li>
                        <li><input id="condition" type="text" class="am-form-field am-input-sm am-input-xm"
                                   placeholder="关键词搜索"/></li>
                        <li><a id="findByName" class="am-btn am-radius am-btn-xs am-btn-success" href="javascript:(0);"
                               style="display: block;margin-top: -1px;">搜索</a></li>
                    </ul>
                </div>
                <script type="text/javascript">
                    $(function () {
                        $("#findByName").click(function () {
                            var condition = $("#condition").val();
                            if (condition == "" || condition == null) {
                                location.href = "<%=basePath%>product?opr=productList&pageSize=8&name=" + "";
                            }
                            location.href = "<%=basePath%>product?opr=productList&pageSize=8&name=" + condition;
                            <%

                            %>
                        })
                    })

                </script>
                <form class="am-form am-g">
                    <table width="100%" class="am-table am-table-bordered am-table-radius am-table-striped">
                        <thead>
                        <tr class="am-success">
                            <th class="table-id">ID</th>
                            <th class="table-title">商品名称</th>
                            <th class="table-type">类别</th>
                            <th>价格</th>
                            <th class="table-date am-hide-sm-only">上架日期</th>
                            <th>库存</th>
                            <th width="163px" class="table-set">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <%
                            int index = Integer.parseInt(session.getAttribute("index").toString());
                            for (Product product : pageVo.getDataList()) {
                        %>
                        <tr>
                            <td><%=index%>
                            </td>
                            <td><a class="txt"><%=product.getName()%>
                            </a></td>
                            <td><%=product.getCategoryLevel()%>
                            </td>
                            <td style="color: #ff473a">￥<%=product.getPrice()%>
                            </td>
                            <td class="am-hide-sm-only"><%=product.getCreateTime()%>
                            </td>
                            <td><%=product.getStock()%>
                            </td>
                            <td>
                                <div class="am-btn-toolbar">
                                    <div class="am-btn-group am-btn-group-xs">
                                        <%--可以添加一个修改单个信息的页面--%>
                                        <a style="display:block;" href="javascript:(0);" id="producInfo"
                                           class="am-btn am-btn-default am-btn-xs am-text-success am-round"><span
                                                class="am-icon-pencil-square-o"></span> </a>
                                        <a onclick="del(<%=product.getId()%>)" style="display:block;"
                                           href="javascript:(0);"
                                           class="am-btn am-btn-default am-btn-xs am-text-danger am-round"><span
                                                class="am-icon-trash-o"></span></a>
                                    </div>
                                </div>
                            </td>
                        </tr>

                        <script type="text/javascript">
                            function del(id) {
                                var result = confirm("您要下架这款商品吗？")
                                if (result) {
                                    location.href = "<%=basePath%>product?opr=del&id=" + id;
                                }
                            }

                            $(function () {
                                $("#producInfo").click(function () {
                                    $("#my-popups").toggle();
                                })
                            })
                        </script>
                        <%
                                index++;
                            }
                        %>
                        </tbody>
                    </table>
                    <center>
                        <%
                            String name = "";
                        %>
                        <a href="<%=basePath%>product?opr=productList&pageSize=8&name=<%=name%>">首页</a>
                        <a href="<%=basePath%>product?opr=productList&pageSize=8&name=<%=name%>&currPageNo=<%=pageVo.getCurrPageNo()-1%>">上一页</a>
                        [<%=pageVo.getCurrPageNo()%>/<%=pageVo.getTotalPageCount()%>]
                        <a href="<%=basePath%>product?opr=productList&pageSize=8&name=<%=name%>&currPageNo=<%=pageVo.getCurrPageNo()+1%>">下一页</a>
                        <a href="<%=basePath%>product?opr=productList&pageSize=8&name=<%=name%>&currPageNo=<%=pageVo.getTotalPageCount()%>">尾页</a>
                    </center>
                    <hr/>

                </form>
            </div>
        </div>
        <%--商品列表结束--%>


        <%--添加商品开始--%>
        <div id="addPorduct">
            <div class="admin-biaogelist">
                <div class="listbiaoti am-cf">
                    <ul class="am-icon-flag on"> 添加商品</ul>
                    <dl class="am-icon-home" style="float: right;"> 当前位置： <a
                            href="<%=basePath%>loginAfter/backManage/backIndex.jsp">首页</a> > <a href="#">添加商品</a></dl>
                </div>

                <div class="fbneirong">
                    <form id="addForm" class="am-form" action="<%=basePath%>product?opr=add" method="post"
                          enctype="multipart/form-data">
                        <div class="am-form-group am-cf">
                            <div class="zuo">商品名称：</div>
                            <div class="you">
                                <input name="name" type="text" class="am-input-sm" id="doc-ipt-email-1"
                                       placeholder="请输入商品名称">
                                <span id="nameError" style="color: #f00;">名称不能为空哦</span>
                            </div>
                        </div>
                        <div class="am-form-group am-cf">
                            <div class="zuo">所属分类：</div>
                            <div class="am-btn-group am-btn-group-xs">
                                <select name="productType"
                                        data-am-selected="{btnWidth: 90, btnSize: 'sm', btnStyle: 'default'}">
                                    <option value="0">产品类型</option>
                                    <%
                                        for (ProductType type : typeList) {
                                    %>
                                    <option value="<%=type.getId()%>"><%=type.getName()%>
                                    </option>
                                    <%
                                        }
                                    %>
                                </select>
                                <span id="typeError" style="color: #f00;">要给产品一个分类哦</span>
                            </div>
                        </div>
                        <div class="am-form-group am-cf">
                            <div class="zuo">价格：</div>
                            <div class="you">
                                <input name="price" type="text" class="am-input-sm" id="doc-ipt-pwd-1" placeholder="元">
                                <span id="priceError" style="color: #f00;">价格要让上帝看得懂哦</span>
                            </div>
                        </div>
                        <div class="am-form-group am-cf">
                            <div class="zuo">描述：</div>
                            <div class="you">
                                <textarea id="description" name="description" class="" rows="2"
                                          id="doc-ta-1"></textarea>
                                <span id="descrError" style="color: #f00;">给您的商品一点点介绍</span>
                            </div>
                        </div>

                        <div class="am-form-group am-cf">
                            <div class="zuo">产品图片：</div>
                            <div class="you" style="height: 45px;">
                                <input type="file" id="doc-ipt-file-1" name="fileName"
                                       accept="image/gif,image/jpg,image/png,image/jpeg">
                                <p class="am-form-help">请选择要上传的文件...</p>
                            </div>
                        </div>

                        <div class="am-form-group am-cf">
                            <div class="zuo">库存：</div>
                            <div class="you" style="height: 45px;">
                                <input name="stock" type="text" class="am-input-sm" placeholder="">
                                <span id="stockError" style="color: #f00;">输入您要上新的数量</span>
                            </div>
                        </div>

                        <div class="am-form-group am-cf">
                            <div class="you" style="margin-left: 11%;">
                                <button type="submit" class="am-btn am-btn-success am-radius"
                                        style="width: 140px; height: 50px;margin-left: 240px;margin-top: 40px">发布
                                </button>
                            </div>
                        </div>
                    </form>
                </div>

            </div>
        </div>
        <%--添加商品结束--%>


    </div>

</div>
<script type="text/javascript">
    $(function () {
        //商品添加div 默认不显示
        $("#addPorduct").hide();

        var $name = $("input[name=name]");
        var $nameError = $("#nameError");
        var $select = $("select[name=productType]");
        var $typeError = $("#typeError");
        var $price = $("input[name=price]");
        var $priceError = $("#priceError");
        var $description = $("#description");
        var $descrError = $("#descrError");
        var $stock = $("input[name=stock]");
        var $stockError = $("#stockError");
        $nameError.hide();
        $typeError.hide();
        $priceError.hide();
        $descrError.hide();
        $stockError.hide();
        $("#addForm").submit(function () {
            if ($name.val() == "" || $name.val() == null) {
                $nameError.show();
                return false;
            } else
                $nameError.hide();
            if ($select.val() == 0) {
                $typeError.show();
                return false;
            } else
                $typeError.hide();
            var priceReg = " /^([1-9][\\d]{0,7}|0)(\\.[\\d]{1,2})?$/";
            if ($price.val() == "" || $price.val() == null) {
                $priceError.show();
                return false;
            } else {
                $priceError.hide();
            }
            /* if (!priceReg.test($price.val())){
                $priceError.show();
                return false;
            }else {
                $priceError.hide();
            }*/
            if ($description.val() == "" || $description.val() == null) {
                $descrError.show();
                return false;
            } else {
                $descrError.hide();
            }
            if ($stock.val() == "" || $stock.val() == null) {
                $stockError.show();
                return false;
            } else
                $stockError.hide();
        })

    })

    //商品添加按钮点击
    function addProductButton(a) {
        $("#productList").hide();
        $("#addPorduct").show();
    }

    //商品列表按钮点击
    function productListButton(a) {
        $("#productList").show();
    }
</script>


<!--[if lt IE 9]>
<script src="<%=basePath%>http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<script src="<%=basePath%>http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="<%=basePath%>assets/js/polyfill/rem.min.js"></script>
<script src="<%=basePath%>assets/js/polyfill/respond.min.js"></script>
<script src="<%=basePath%>assets/js/amazeui.legacy.js"></script>
<![endif]-->

<!--[if (gte IE 9)|!(IE)]><!-->
<script src="<%=basePath%>assets/js/amazeui.min.js"></script>
<!--<![endif]-->


</body>
</html>